<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateGroupBuysTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('group_buys', function (Blueprint $table) {
            $table->id();
            $table->string('name')->comment('活动名称');
            $table->string('describe')->nullable()->comment('描述');
            $table->string('body')->nullable()->comment('介绍');
            $table->string('thumb')->nullable()->comment('活动封面');
            $table->tinyInteger('type', false, true)->index()->comment('资源类型:1=专栏、2=学科、3=文档');
            $table->integer('data_id', false, true)->index()->comment('资源id');
            $table->tinyInteger('member_num')->default(0)->index()->comment('成团人数');
            $table->decimal('original_price')->default(0)->index()->comment('原价格');
            $table->decimal('leader_price')->default(0)->index()->comment('团长价格');
            $table->decimal('member_price')->default(0)->index()->comment('团员价格');
            $table->tinyInteger('is_active')->default(0)->index()->comment('是否上架：0=否，1=是');
            $table->tinyInteger('is_public')->default(0)->index()->comment('是否公开：0=否，1=是');
            $table->tinyInteger('must_join')->default(0)->index()->comment('必须拼团才能购买：0=否，1=是');
            $table->tinyInteger('effective_type')->default(4)->index()->comment('有效类型：1=天数，2=小时，3=日期，4=长期');
            $table->integer('effective_days')->nullable()->index()->comment('有效天数');
            $table->integer('effective_hours')->nullable()->index()->comment('有效小时数');
            $table->dateTime('effective_date')->nullable()->index()->comment('有效日期');
            $table->string('member_ids')->nullable()->comment('已参与团员ids数组');
            $table->timestamps();
        });

        DB::statement("ALTER TABLE group_buys comment '拼团活动'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('group_buys');
    }
}
